/// FOCUSdata 
/// Scott Fisher, Graig R. Klein, Juste Codjo


**********************************************************
**********************************************************
**********************************************************

////  AS DETAILED IN THE ARTICLE, ALL ORIGINAL DATA IS AVAILABLE ON 
////  https://focusdataproject.com/ & HARVARD'S DATAVERSE & BY REQUEST 
////  TO SCOTT FISHER (sfisher1@njcu.edu)

**********************************************************
**********************************************************
**********************************************************

log using "/Users/Graig/Downloads/FPA trial.smcl", replace

** Table 1
// description of data based on dataset at time of writing


** Table 2
use "/Users/Graig/Downloads/FOCUSdata - sentiment from media & MOFA.dta", replace

sum sentiment if Sputnik == 1
sum sentiment if RT == 1
sum sentiment if Peoples_Daily == 1
sum sentiment if Global_Times == 1
sum sentiment if IRNA == 1
sum sentiment if KCNA == 1
sum sentiment if Rodong == 1

sum sentiment if China == 1
sum sentiment if Russia == 1
sum sentiment if Iran == 1
sum ordinal_sentiment if China == 1

** Figure 1: Peoples' Daily Sentiment
twoway (scatter sentiment dt if year>2007 & Peoples_Daily == 1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(17532 "2008" 17898 "2009" 18263 "2010" 18628 "2011" 18993 "2012" 19360 "2013" 19724 "2014" 20089 "2015" 20454 "2016" 20820 "2017" 21185 "2018" 21550 "2019" 21915 "2020", labsize(vsmall))) (line average_daily_sentiment dt if year>2007 & Peoples_Daily == 1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(PeoplesDailydaily, replace)


** Figure 2: Global Times Sentiment
twoway (scatter sentiment dt if Global_Times == 1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(#12, labsize(vsmall))) (line average_daily_sentiment dt if Global_Times == 1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(GlobalTimesdaily, replace)


** Figure 3: Russian MOFA Sentiment by Topic
// figure is generated using Tableau

/** 
Russia MOFA database (as an Excel file)

Once that Excel file is loaded into Tableau, ensure all three sheets from the Excel file are connected in Tableau's Data Source tab - drag over the 'duplicates, errors removed' sheet, then drag over the other two sheets; connect them with 'duplicates, errors removed' using Article Content and Text1.

1. To recreate the Baseline figure (in any order):
2. Open a new sheet and drag Polarity1 from the Global Sentiment Analysis table onto the Color mark.
3. Drag 'duplicates, errors removed (Count)' onto the Size mark.
4. Drag Polarity1 to the Label mark.
5. If Tableau doesn't default to Treemaps (the image style for our figures), click the Show Me button on the far upper right in Tableau and select Treemaps.
6. To recreate the figures for Panel B (Freedom House) and Panel C (U.S. Sanctions), duplicate the sheet we just created. To duplicate a sheet in Tableau, right click on the sheet name and select duplicate. Once duplicated:
7. Drag Text1 to filters.
8. Once in Filters, hover over the new filter and click on the little white triangle that appears. Once you click on the triangle, select 'Show Filter' from the dropdown menu. The filter (a little box labeled Text1) should appear on the far right in Tableau.
9. Hover over the new box and another little triangle should appear. Click the triangle and select 'Wildcard Match' from the dropdown menu. This is important. Without selecting Wildcard Match it won't work properly. 
10. Enter text (i.e. Freedom House) into the Text1 box and hit return/enter. A figure should appear that replicates our Figure 2. Erase/Delete Freedom House and enter U.S. sanctions and a figure similar to our Figure 3 should appear. 
11. It is important to note that depending on the size of your screen, the layout of the figures may slightly vary. The initial images were generated on a laptop; larger screens may produce different layouts. The ratios remain the same however.

**/


** Figure 4: IRNA Sentiment Obama vs. Trump Daily

collapse (mean) sentiment subjectivity year month day if IRNA==1, by(dt)

gen date2 = dt

gen obama = 1 if date2<20767
gen trump = 1 if date2>20766 & date2<20839
gen trump2 = 1 if date2>20838 & date2<21934

egen avgsentiment_obama = mean(sentiment) if obama==1
egen avgsentiment_trump = mean(sentiment) if trump==1
egen avgsentiment_trump2 = mean(sentiment) if trump2==1

twoway scatter sentiment date2, msize(vsmall) xline(20767) xline(20839) || lfit sentiment date2 if date2<20767 || lfit sentiment date2 if date2>20766 & date2<20839 || lfit sentiment date2 if date2>20838 & date2<21934


** Table A1: IRNA Sentiment t-test
gen term = .
replace term = 1 if obama == 1
replace term = 2 if trump2 == 1

ttest sentiment, by(term)
ttest sentiment, by(term) unequal


** Figure 5: IRNA Sentiment Obama vs. Trump Monthly
// figure is generated using Tableau on the FOCUSdata website

// 1. go to https://focusdataproject.com/iran/irans-islamic-republic-news-agency/
// 2. in search box in top right, type Obama
// 3. in search box in top right, type Trump


** Figure A1: IRNA Average Daily Sentiment 
use "/Users/Graig/Downloads/FOCUSdata - sentiment from media & MOFA.dta", replace

twoway (scatter sentiment dt if IRNA==1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall))) (line average_daily_sentiment dt if IRNA==1, sort lcolor(black) lwidth(vthin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(IRNAdaily, replace)


** Figure A2: Sputnik Average Daily Sentiment 
twoway (scatter sentiment dt if Sputnik==1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall))) (line average_daily_sentiment dt if Sputnik==1, sort lcolor(black) lwidth(vthin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(SPUTNIKdaily, replace)


** Figure A3: RT Average Daily Sentiment 
twoway (scatter sentiment dt if RT==1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall))) (line average_daily_sentiment dt if RT==1, sort lcolor(black) lwidth(vthin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(RTdaily, replace)


** Figure A4: KCNA Average Daily Sentiment
twoway (scatter sentiment dt if KCNA==1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall))) (line average_daily_sentiment dt if KCNA==1, sort lcolor(black) lwidth(vthin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(KCNAdaily, replace)


** Figure A5: Rodong Average Daily Sentiment 
twoway (scatter sentiment dt if Rodong==1, mcolor(gs15) msize(vsmall) mlcolor(gs13) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall))) (line average_daily_sentiment dt if Rodong==1, sort lcolor(black) lwidth(vthin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(RODONGdaily, replace)


** Figure A6: Iran MOFA Average Monthly Sentiment 
twoway (scatter sentiment dt if Iran==1, mcolor(gs15) msize(vsmall) mlcolor(gs14) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(, labsize(vsmall))) (line average_monthly_sentiment dt if Iran==1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Monthly sentiment"))), name(IRANmonthly, replace)


** Figure A7: Russia MOFA Average Monthly Sentiment 
twoway (scatter sentiment dt if Russia==1, mcolor(gs15) msize(small) mlcolor(gs14) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(#10, labsize(vsmall)) xtick(#19)) (line average_monthly_sentiment dt if Russia==1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Monthly sentiment"))), name(RUSSIAmonthly, replace)


** Figure A8: China MOFA Average Monthly Sentiment
twoway (scatter sentiment dt if China==1, mcolor(gs15) msize(small) mlcolor(gs14) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(#10, labsize(vsmall)) xtick(#19)) (line average_monthly_sentiment dt if China==1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Monthly sentiment"))), name(CHINAmonthly, replace)

**** Figure A9: Iran MOFA Average Daily Sentiment 
twoway (scatter sentiment dt if Iran==1, mcolor(gs15) msize(vsmall) mlcolor(gs14) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(, labsize(vsmall))) (line average_daily_sentiment dt if Iran==1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(IRANdaily, replace)


**** Figure A10: Russia MOFA Average Daily Sentiment 
twoway (scatter sentiment dt if Russia==1, mcolor(gs15) msize(vsmall) mlcolor(gs14) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(, labsize(vsmall))) (line average_daily_sentiment dt if Russia==1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(RUSSIAdaily, replace)


**** Figure A11: China MOFA Average Daily Sentiment 
twoway (scatter sentiment dt if China==1, mcolor(gs15) msize(vsmall) mlcolor(gs14) mlwidth(vthin) ytitle(sentiment, size(vsmall)) ylabel(-1(.5)1, labsize(vsmall) angle(horizontal)) ytick(-1(.25)1) xtitle(Year, size(vsmall)) xlabel(, labsize(vsmall))) (line average_daily_sentiment dt if China==1, sort lcolor(black) lwidth(thin) graphregion(fcolor(white) margin(medium) lcolor(white)) legend(symxsize(4) rowgap(tiny) colgap(small) keygap(tiny) size(vsmall) lcolor(white) lab(1 "sentiment per Article") lab(2 "Average Daily sentiment"))), name(CHINAdaily, replace)


log close














